home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 November / november_2001.iso / Browsers / Netscape 6.1 / browser.xpi / bin / chrome / comm.jar / content / editor / EdInsertChars.js < prev    next >
Encoding:
JavaScript  |  2001-03-21  |  14.3 KB  |  572 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Baki Bon <bakibon@yahoo.com>   (original author)
  22.  */
  23.  
  24. //------------------------------------------------------------------
  25. // From Unicode 3.0 Page 54. 3.11 Conjoining Jamo Behavior
  26. var SBase = 0xac00;
  27. var LBase = 0x1100;
  28. var VBase = 0x1161;
  29. var TBase = 0x11A7;
  30. var LCount = 19;
  31. var VCount = 21;
  32. var TCount = 28;
  33. var NCount = VCount * TCount;
  34. // End of Unicode 3.0
  35.  
  36. // dialog initialization code
  37. function Startup()
  38. {
  39.   if (!InitEditorShell())
  40.     return;
  41.  
  42.   StartupLatin();
  43.  
  44.   doSetOKCancel(onOK, Cancel);
  45.  
  46.  
  47.   // Dialog is non-modal:
  48.   // Change "Ok" to "Insert, change "Cancel" to "Close"
  49.   var okButton = document.getElementById("ok");
  50.   if (okButton)
  51.     okButton.setAttribute("label", GetString("Insert"));
  52.  
  53.   var cancelButton = document.getElementById("cancel");
  54.   if (cancelButton)
  55.     cancelButton.setAttribute("label", GetString("Close"));
  56.  
  57.   // Set a variable on the opener window so we
  58.   //  can track ownership of close this window with it
  59.   window.opener.InsertCharWindow = window;
  60.   window.sizeToContent();
  61.  
  62.   SetWindowLocation();
  63. }
  64.  
  65. function onOK()
  66. {
  67.   // Insert the character
  68.   // Note: Assiated parent window and editorShell
  69.   //  will be changed to whatever editor window has the focus
  70.   window.editorShell.InsertSource(LatinChar);
  71.  
  72.   // Set persistent attributes to save
  73.   //  which category, letter, and character modifier was used
  74.   CategoryGroup.setAttribute("category", category);
  75.   CategoryGroup.setAttribute("letter_index", indexL);
  76.   CategoryGroup.setAttribute("char_index", indexM);
  77.  
  78.   // Return true only for modal window
  79.   //return true;
  80. }
  81.  
  82. function Cancel()
  83. {
  84.   window.opener.InsertCharWindow = null;
  85.   SaveWindowLocation();
  86.   window.close();
  87. }
  88.  
  89. //------------------------------------------------------------------
  90. var LatinL;
  91. var LatinM;
  92. var LatinL_Label;
  93. var LatinM_Label;
  94. var LatinChar;
  95. var indexL=0;
  96. var indexM=0;
  97. var indexM_AU=0;
  98. var indexM_AL=0;
  99. var indexM_U=0;
  100. var indexM_L=0;
  101. var indexM_S=0;
  102. var LItems=0;
  103. var category;
  104. var CategoryGroup;
  105. var initialize = true;
  106.  
  107. function StartupLatin()
  108. {
  109.  
  110.   LatinL = document.getElementById("LatinL");
  111.   LatinM = document.getElementById("LatinM");
  112.   LatinL_Label = document.getElementById("LatinL_Label");
  113.   LatinM_Label = document.getElementById("LatinM_Label");
  114.  
  115.   var Symbol      = document.getElementById("Symbol");
  116.   var AccentUpper = document.getElementById("AccentUpper");
  117.   var AccentLower = document.getElementById("AccentUpper");
  118.   var Upper       = document.getElementById("Upper");
  119.   var Lower       = document.getElementById("Lower");
  120.   CategoryGroup   = document.getElementById("CatGrp");
  121.  
  122.   // Initialize which radio button is set from persistent attribute...
  123.   var category = CategoryGroup.getAttribute("category");
  124.  
  125.   // ...as well as indexes into the letter and character lists
  126.   var index = Number(CategoryGroup.getAttribute("letter_index"));
  127.   if (index && index >= 0)
  128.     indexL = index;
  129.   index = Number(CategoryGroup.getAttribute("char_index"));
  130.   if (index && index >= 0)
  131.     indexM = index;
  132.  
  133.  
  134.   switch (category)
  135.   {
  136.     case "AccentUpper": // Uppercase Diacritical
  137.       AccentUpper.checked = true;
  138.       indexM_AU = indexM;
  139.       break;
  140.     case "AccentLower": // Lowercase Diacritical
  141.       AccentLower.checked = true;
  142.       indexM_AL = indexM;
  143.       break;
  144.     case "Upper": // Uppercase w/o Diacritical
  145.       Upper.checked = true;
  146.       indexM_U = indexM;
  147.       break;
  148.     case "Lower": // Lowercase w/o Diacritical
  149.       Lower.checked = true;
  150.       indexM_L = indexM;
  151.       break;
  152.     default:
  153.       category = "Symbol";
  154.       Symbol.checked = true;
  155.       indexM_S = indexM;
  156.       break;
  157.   }
  158.  
  159.   ChangeCategory(category);
  160.   initialize = false;
  161. }
  162.  
  163. function ChangeCategory(newCategory)
  164. {
  165.   if (category != newCategory || initialize)
  166.   {
  167.     category = newCategory;
  168.     // Note: Must do L before M to set LatinL.selectedIndex
  169.     UpdateLatinL();
  170.     UpdateLatinM();
  171.     UpdateCharacter();
  172.   }
  173. }
  174.  
  175. function SelectLatinLetter()
  176. {
  177.   if(LatinL.selectedIndex != indexL )
  178.   {
  179.     indexL = LatinL.selectedIndex;
  180.     UpdateLatinM();
  181.     UpdateCharacter();
  182.   }
  183. }
  184.  
  185. function SelectLatinModifier()
  186. {
  187.   if(LatinM.selectedIndex != indexM )
  188.   {
  189.     indexM = LatinM.selectedIndex;
  190.     UpdateCharacter();
  191.   }
  192. }
  193. function DisableLatinL(disable)
  194. {
  195.   LatinL_Label.setAttribute("disabled", disable ? "true" : "false");
  196. }
  197.  
  198. function UpdateLatinL()
  199. {
  200.   ClearMenulist(LatinL);
  201.   if (category == "AccentUpper" || category == "AccentLower")
  202.   {
  203.     DisableLatinL(false);
  204.     var basic;
  205.  
  206.     // Fill the list
  207.     if (category == "AccentUpper")   // Uppercase Diacritical
  208.     {
  209.       for(basic=0; basic < 26; basic++)
  210.         AppendStringToMenulist(LatinL , String.fromCharCode(0x41 + basic));
  211.     }
  212.     else  // Lowercase Diacritical
  213.     {
  214.       for(basic=0; basic < 26; basic++)
  215.        AppendStringToMenulist(LatinL , String.fromCharCode(0x61 + basic));
  216.     }
  217.     // Set the selected item
  218.     if (indexL > 25)
  219.       indexL = 25;
  220.     LatinL.selectedIndex = indexL;
  221.   }
  222.   else
  223.   {
  224.     // Other categories don't hinge on a "letter"
  225.     DisableLatinL(true);
  226.     // Note: don't change the indexL so it can be used next time
  227.   }
  228. }
  229.  
  230. function UpdateLatinM()
  231. {
  232.   ClearMenulist(LatinM);
  233.   var i, basic;
  234.   switch(category)
  235.   {
  236.     case "AccentUpper": // Uppercase Diacritical
  237.       for(basic=0; basic < upper[indexL].length; basic++)
  238.         AppendStringToMenulist(LatinM ,
  239.              String.fromCharCode(upper[indexL][basic]));
  240.  
  241.       if(indexM_AU < upper[indexL].length)
  242.         indexM = indexM_AU;
  243.       else
  244.         indexM = upper[indexL].length - 1;
  245.       indexM_AU = indexM;
  246.       break;
  247.  
  248.     case "AccentLower": // Lowercase Diacritical
  249.       for(basic=0; basic < lower[indexL].length; basic++)
  250.         AppendStringToMenulist(LatinM ,
  251.              String.fromCharCode(lower[indexL][basic]));
  252.  
  253.       if(indexM_AL < lower[indexL].length)
  254.         indexM = indexM_AL;
  255.       else
  256.         indexM = lower[indexL].length - 1;
  257.       indexM_AL = indexM;
  258.       break;
  259.  
  260.     case "Upper": // Uppercase w/o Diacritical
  261.       for(i=0; i < otherupper.length; i++)
  262.         AppendStringToMenulist(LatinM, String.fromCharCode(otherupper[i]));
  263.  
  264.       if(indexM_U < otherupper.length)
  265.         indexM = indexM_U;
  266.       else
  267.         indexM = otherupper.length - 1;
  268.       indexM_U = indexM;
  269.       break;
  270.  
  271.     case "Lower": // Lowercase w/o Diacritical
  272.       for(i=0; i < otherlower.length; i++)
  273.         AppendStringToMenulist(LatinM , String.fromCharCode(otherlower[i]));
  274.  
  275.       if(indexM_L < otherlower.length)
  276.         indexM = indexM_L;
  277.       else
  278.         indexM = otherlower.length - 1;
  279.       indexM_L = indexM;
  280.       break;
  281.  
  282.     case "Symbol": // Symbol
  283.       for(i=0; i < symbol.length; i++)
  284.         AppendStringToMenulist(LatinM , String.fromCharCode(symbol[i]));
  285.  
  286.       if(indexM_S < symbol.length)
  287.         indexM = indexM_S;
  288.       else
  289.         indexM = symbol.length - 1;
  290.       indexM_S = indexM;
  291.       break;
  292.   }
  293.   LatinM.selectedIndex = indexM;
  294. }
  295.  
  296. function UpdateCharacter()
  297. {
  298.   indexM = LatinM.selectedIndex;
  299.  
  300.   switch(category)
  301.   {
  302.     case "AccentUpper": // Uppercase Diacritical
  303.       LatinChar = String.fromCharCode(upper[indexL][indexM]);
  304.       indexM_AU = indexM;
  305.       break;
  306.     case "AccentLower": // Lowercase Diacritical
  307.       LatinChar = String.fromCharCode(lower[indexL][indexM]);
  308.       indexM_AL = indexM;
  309.       break;
  310.     case "Upper": // Uppercase w/o Diacritical
  311.       LatinChar = String.fromCharCode(otherupper[indexM]);
  312.       indexM_U = indexM;
  313.       break;
  314.     case "Lower": // Lowercase w/o Diacritical
  315.       LatinChar = String.fromCharCode(otherlower[indexM]);
  316.       indexM_L = indexM;
  317.       break;
  318.     case "Symbol":
  319.       LatinChar =  String.fromCharCode(symbol[indexM]);
  320.       indexM_S = indexM;
  321.       break;
  322.   }
  323. //dump("Letter Index="+indexL+", Character Index="+indexM+", Character = "+LatinChar+"\n");
  324. }
  325.  
  326. var upper=[
  327. [ // A
  328.   0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5,
  329.   0x0100, 0x0102, 0x0104, 0x01cd, 0x01de, 0x01de, 0x01e0, 0x01fa,
  330.   0x0200, 0x0202, 0x0226,
  331.   0x1e00, 0x1ea0, 0x1ea2, 0x1ea4, 0x1ea6, 0x1ea8, 0x1eaa, 0x1eac,
  332.   0x1eae, 0x1eb0, 0x1eb2, 0x1eb4, 0x1eb6
  333. ], [ // B
  334.   0x0181, 0x0182, 0x0184,
  335.   0x1e02, 0x1e04, 0x1e06
  336. ], [ // C
  337.   0x00c7, 0x0106, 0x0108, 0x010a, 0x010c,
  338.   0x0187,
  339.   0x1e08
  340. ], [ // D
  341.   0x010e, 0x0110,
  342.   0x0189,
  343.   0x018a,
  344.   0x1e0a, 0x1e0c, 0x1e0e, 0x1e10, 0x1e12
  345. ], [ // E
  346.   0x00C8, 0x00C9, 0x00CA, 0x00CB,
  347.   0x0112, 0x0114, 0x0116, 0x0118, 0x011A,
  348.   0x0204, 0x0206, 0x0228,
  349.   0x1e14, 0x1e16, 0x1e18, 0x1e1a, 0x1e1c,
  350.   0x1eb8, 0x1eba, 0x1ebc, 0x1ebe, 0x1ec0, 0x1ec2, 0x1ec4, 0x1ec6
  351. ], [ // F
  352.   0x1e1e
  353. ], [ // G
  354.   0x011c, 0x011E, 0x0120, 0x0122,
  355.   0x01e4, 0x01e6, 0x01f4,
  356.   0x1e20
  357. ], [ // H
  358.   0x0124, 0x0126,
  359.   0x021e,
  360.   0x1e22, 0x1e24, 0x1e26, 0x1e28, 0x1e2a
  361. ], [ // I
  362.   0x00CC, 0x00CD, 0x00CE, 0x00CF,
  363.   0x0128, 0x012a, 0x012C, 0x012e, 0x0130,
  364.   0x0208, 0x020a,
  365.   0x1e2c, 0x1e2e,
  366.   0x1ec8, 0x1eca
  367. ], [ // J
  368.   0x0134,
  369.   0x01f0
  370. ], [ // K
  371.   0x0136,
  372.   0x0198, 0x01e8,
  373.   0x1e30, 0x1e32, 0x1e34
  374. ], [ // L
  375.   0x0139, 0x013B, 0x013D, 0x013F, 0x0141,
  376.   0x1e36, 0x1e38, 0x1e3a, 0x1e3c
  377. ], [ // M
  378.   0x1e3e, 0x1e40, 0x1e42
  379. ], [ // N
  380.   0x00D1,
  381.   0x0143, 0x0145, 0x0147, 0x014A,
  382.   0x01F8,
  383.   0x1e44, 0x1e46, 0x1e48, 0x1e4a
  384. ], [ // O
  385.   0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6,
  386.   0x014C, 0x014E, 0x0150,
  387.   0x01ea, 0x01ec,
  388.   0x020c, 0x020e, 0x022A, 0x022C, 0x022E, 0x0230,
  389.   0x1e4c, 0x1e4e, 0x1e50, 0x1e52,
  390.   0x1ecc, 0x1ece, 0x1ed0, 0x1ed2, 0x1ed4, 0x1ed6, 0x1ed8, 0x1eda, 0x1edc, 0x1ede,
  391.   0x1ee0, 0x1ee2
  392. ], [ // P
  393.   0x1e54, 0x1e56
  394. ], [ // Q
  395.   0x0051
  396. ], [ // R
  397.   0x0154, 0x0156, 0x0158,
  398.   0x0210, 0x0212,
  399.   0x1e58, 0x1e5a, 0x1e5c, 0x1e5e
  400. ], [ // S
  401.   0x015A, 0x015C, 0x015E, 0x0160,
  402.   0x0218,
  403.   0x1e60, 0x1e62, 0x1e64, 0x1e66, 0x1e68
  404. ], [ // T
  405.   0x0162, 0x0164, 0x0166,
  406.   0x021A,
  407.   0x1e6a, 0x1e6c, 0x1e6e, 0x1e70
  408. ], [ // U
  409.   0x00D9, 0x00DA, 0x00DB, 0x00DC,
  410.   0x0168, 0x016A, 0x016C, 0x016E, 0x0170, 0x0172,
  411.   0x0214, 0x0216,
  412.   0x1e72, 0x1e74, 0x1e76, 0x1e78, 0x1e7a,
  413.   0x1ee4, 0x1ee6, 0x1ee8, 0x1eea, 0x1eec, 0x1eee, 0x1ef0
  414. ], [ // V
  415.   0x1e7c, 0x1e7e
  416. ], [ // W
  417.   0x0174,
  418.   0x1e80, 0x1e82, 0x1e84, 0x1e86, 0x1e88
  419. ], [ // X
  420.   0x1e8a, 0x1e8c
  421. ], [ // Y
  422.   0x00DD,
  423.   0x0176, 0x0178,
  424.   0x0232,
  425.   0x1e8e,
  426.   0x1ef2, 0x1ef4, 0x1ef6, 0x1ef8
  427. ], [ // Z
  428.   0x0179, 0x017B, 0x017D,
  429.   0x0224,
  430.   0x1e90, 0x1e92, 0x1e94
  431. ] ];
  432. var lower=[
  433. [ // a
  434.   0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5,
  435.   0x0101, 0x0103, 0x0105,
  436.   0x01ce, 0x01df, 0x01e1, 0x01fb,
  437.   0x0201, 0x0203, 0x0227,
  438.   0x1e01, 0x1e9a,
  439.   0x1ea1, 0x1ea3, 0x1ea5, 0x1ea7, 0x1ea9, 0x1eab, 0x1ead, 0x1eaf,
  440.   0x1eb1, 0x1eb3, 0x1eb5, 0x1eb7
  441. ], [ // b
  442.   0x0180, 0x0183, 0x0185,
  443.   0x1e03, 0x1e05, 0x1e07
  444. ], [ // c
  445.   0x00e7,
  446.   0x0107, 0x0109, 0x010b, 0x010d,
  447.   0x0188,
  448.   0x1e09
  449. ], [ // d
  450.   0x010f, 0x0111,
  451.   0x1e0b, 0x1e0d, 0x1e0f, 0x1e11, 0x1e13
  452. ], [ // e
  453.   0x00e8, 0x00e9, 0x00ea, 0x00eb,
  454.   0x0113, 0x0115, 0x0117, 0x0119, 0x011b,
  455.   0x0205, 0x0207, 0x0229,
  456.   0x1e15, 0x1e17, 0x1e19, 0x1e1b, 0x1e1d,
  457.   0x1eb9, 0x1ebb, 0x1ebd, 0x1ebf,
  458.   0x1ec1, 0x1ec3, 0x1ec5, 0x1ec7
  459. ], [ // f
  460.   0x1e1f
  461. ], [ // g
  462.   0x011d, 0x011f, 0x0121, 0x0123,
  463.   0x01e5, 0x01e7, 0x01f5,
  464.   0x1e21
  465. ], [ // h
  466.   0x0125, 0x0127,
  467.   0x021f,
  468.   0x1e23, 0x1e25, 0x1e27, 0x1e29, 0x1e2b, 0x1e96
  469. ], [ // i
  470.   0x00ec, 0x00ed, 0x00ee, 0x00ef,
  471.   0x0129, 0x012b, 0x012d, 0x012f, 0x0131,
  472.   0x01d0,
  473.   0x0209, 0x020b,
  474.   0x1e2d, 0x1e2f,
  475.   0x1ec9, 0x1ecb
  476. ], [ // j
  477.   0x0135,
  478. ], [ // k
  479.   0x0137, 0x0138,
  480.   0x01e9,
  481.   0x1e31, 0x1e33, 0x1e35
  482. ], [ // l
  483.   0x013a, 0x013c, 0x013e, 0x0140, 0x0142,
  484.   0x1e37, 0x1e39, 0x1e3b, 0x1e3d
  485. ], [ // m
  486.   0x1e3f, 0x1e41, 0x1e43
  487. ], [ // n
  488.   0x00f1,
  489.   0x0144, 0x0146, 0x0148, 0x0149, 0x014b,
  490.   0x01f9,
  491.   0x1e45, 0x1e47, 0x1e49, 0x1e4b
  492. ], [ // o
  493.   0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6,
  494.   0x014d, 0x014f, 0x0151,
  495.   0x01d2, 0x01eb, 0x01ed,
  496.   0x020d, 0x020e, 0x022b, 0x22d, 0x022f, 0x0231,
  497.   0x1e4d, 0x1e4f, 0x1e51, 0x1e53,
  498.   0x1ecd, 0x1ecf,
  499.   0x1ed1, 0x1ed3, 0x1ed5, 0x1ed7, 0x1ed9, 0x1edb, 0x1edd, 0x1edf,
  500.   0x1ee1, 0x1ee3
  501. ], [ // p
  502.   0x1e55, 0x1e57
  503. ], [ // q
  504.   0x0071
  505. ], [ // r
  506.   0x0155, 0x0157, 0x0159,
  507.   0x0211, 0x0213,
  508.   0x1e59, 0x1e5b, 0x1e5d, 0x1e5f
  509. ], [ // s
  510.   0x015b, 0x015d, 0x015f, 0x0161,
  511.   0x0219,
  512.   0x1e61, 0x1e63, 0x1e65, 0x1e67, 0x1e69
  513. ], [ // t
  514.   0x0162, 0x0163, 0x0165, 0x0167,
  515.   0x021b,
  516.   0x1e6b, 0x1e6d, 0x1e6f, 0x1e71,
  517.   0x1e97
  518. ], [ // u
  519.   0x00f9, 0x00fa, 0x00fb, 0x00fc,
  520.   0x0169, 0x016b, 0x016d, 0x016f, 0x0171, 0x0173,
  521.   0x01d4, 0x01d6, 0x01d8, 0x01da, 0x01dc,
  522.   0x0215, 0x0217,
  523.   0x1e73, 0x1e75, 0x1e77, 0x1e79, 0x1e7b,
  524.   0x1ee5, 0x1ee7, 0x1ee9, 0x1eeb, 0x1eed, 0x1eef,
  525.   0x1ef1
  526. ], [ // v
  527.   0x1e7d, 0x1e7f
  528. ], [ // w
  529.   0x0175,
  530.   0x1e81, 0x1e83, 0x1e85, 0x1e87, 0x1e89, 0x1e98,
  531. ], [ // x
  532.   0x1e8b, 0x1e8d
  533. ], [ // y
  534.   0x00fd, 0x00ff,
  535.   0x0177,
  536.   0x0233,
  537.   0x1e8f, 0x1e99, 0x1ef3, 0x1ef5, 0x1ef7, 0x1ef9
  538. ], [ // z
  539.   0x017a, 0x017c, 0x017e,
  540.   0x0225,
  541.   0x1e91, 0x1e93, 0x1e95
  542. ] ];
  543.  
  544.  
  545. var symbol = [
  546.         0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
  547. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac,         0x00ae, 0x00af,
  548. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
  549. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
  550. 0x00d7, 0x00f7
  551. ];
  552.  
  553. var otherupper = [
  554. 0x00c6, 0x00d0, 0x00d8, 0x00de,
  555. 0x0132,
  556. 0x0152,
  557. 0x0186,
  558. 0x01c4, 0x01c5,
  559. 0x01c7, 0x01c8,
  560. 0x01ca, 0x01cb,
  561. 0x01F1, 0x01f2
  562. ];
  563. var otherlower = [
  564. 0x00e6, 0x00f0, 0x00f8, 0x00fe, 0x00df,
  565. 0x0133,
  566. 0x0153,
  567. 0x01c6,
  568. 0x01c9,
  569. 0x01cc,
  570. 0x01f3
  571. ];
  572.